package com.atlanta.adopt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;

public class ExpNetTask extends AsyncTask<String,String,Bitmap> {
	private Bitmap[] doggies;
	private Document doc;
	public Bitmap[] getDoggies(){
		return doggies;
	}
	
/*	protected Document doInBackground(Object... arg0) {
		String URL = "http://sms.petpoint.com/webservices/adoptablesearch/wsAdoptableAnimals.aspx?location=HM-Adoption&stage=Available&species=Dog&sex=A&agegroup=All&onhold=A&orderby=ID&colnum=3&authkey=uj36rnuzp324mmby22csi3mbfbt4y4p1h38ahympi8f5h6vyto&css=http://www.atlantahumane.org/css/pets.css";
        try {
			doc =  Jsoup.connect(URL).get();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		//acc = doc.text()
        return doc;
		
	}*/
	protected Bitmap doInBackground(String... url){
		InputStream is= null;
	    Bitmap bm= null;
	    try{
	        HttpGet httpRequest = new HttpGet(url[0]);//bitmapUrl.toURI());
	        HttpClient httpclient = new DefaultHttpClient();
	        HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

	        HttpEntity entity = response.getEntity();
	        BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
	        is = bufHttpEntity.getContent();
	        bm = BitmapFactory.decodeStream(is); 
	    }catch ( MalformedURLException e ){
	        Log.d( "RemoteImageHandler", "fetchImage passed invalid URL: " + url );
	    }catch ( IOException e ){
	        Log.d( "RemoteImageHandler", "fetchImage IO exception: " + e );
	    }finally{
	        if(is!=null)try{
	            is.close();
	        }catch(IOException e){}
	    }
	    return bm;

}
}

